package org.example.fancystudy.volatiles;

import java.util.concurrent.TimeUnit;

/**
 * @author chaigq
 * @version 1.0
 * @date 2023/2/16 10:48
 */
public class VolatileSeeDemo {

    //static boolean boolValue = true;
    static volatile boolean boolValue = true;
    public static void main(String[] args) {
        new Thread(() -> {
            System.out.println(Thread.currentThread().getName()+"\t -----come in");
            while (boolValue){

            }
            System.out.println(Thread.currentThread().getName()+"\t -----flag被设置为false，程序停止");
        },"t1").start();
        try {
            TimeUnit.SECONDS.sleep(2);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
        boolValue = false;
        System.out.println(Thread.currentThread().getName()+"\t 修改完成flag: " + boolValue);
    }
}
